package com.test.blogsystem.Controller;

import com.test.blogsystem.Pojo.Require.LoginInfo;
import com.test.blogsystem.Pojo.Response.UserInfoResponse;
import com.test.blogsystem.Pojo.Response.UserLoginResponse;
import com.test.blogsystem.Service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
@Slf4j
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;

    @RequestMapping("/login")
    public UserLoginResponse login(@RequestBody @Validated LoginInfo loginInfo) {
        log.info("用户信息：{}",loginInfo);
        UserLoginResponse userLoginResponse = userService.checkPassword(loginInfo);
        return userLoginResponse;
    }

    @RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull(message = "userId不能为空") Integer userId){
        return userService.getUserInfo(userId);
    }

    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull(message = "blogId不能为空") Integer blogId){
        return userService.getAuthorInfo(blogId);
    }
}
